package com.gfdd.tea.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gfdd.tea.common.R;
import com.gfdd.tea.dto.TeasDto;
import com.gfdd.tea.pojo.Teas;
import com.gfdd.tea.service.TeasService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/teas")
@Slf4j
public class TeasController {
    @Autowired
    private TeasService teasService;
    @GetMapping("/page")
    public R<Page<Teas>> getTeasPage(Long page,Long pageSize,String name){
        Page<Teas> pageInfo =new Page<>(page,pageSize);
        LambdaQueryWrapper<Teas> wrapper=new LambdaQueryWrapper<>();
        wrapper.orderByDesc(Teas::getCreateTime).orderByDesc(Teas::getUpdateTime);
        wrapper.like(name!=null,Teas::getTeaName,name);
        teasService.page(pageInfo,wrapper);
        return R.success(pageInfo);
    }
   /* @GetMapping("/set")
    public R<String> setTea(){
        Teas teas=new Teas();
        teas.setPrice((long) 50);
        teas.setTeaName("凤凰单丛");
        teas.setSalePrice((long) 500);
        teas.setDescription("天然姜花香气馥郁持久，滋味浓醇爽口，有明显的姜花“特韵”，回味甘滑，极耐冲泡，饮之齿颊生香，成茶到年底“返春”回香，香味更佳");
        teasService.save(teas);
        return R.success("保存成功");
    }*/

    /**
     * 根据id查询茶叶详情页
     * @param id
     * @return
     */
   @GetMapping("/getTeasDetail")
   public R<TeasDto> getTeasDtoInfoById(Long id){
        log.info(id.toString());
       TeasDto teasDto = teasService.queryTeasWithAssess(id);
       return R.success(teasDto);
   }
};
